#!/bin/bash
if [ ! -n "${1}" ] || [ ! -n "${2}" ] || [ ! -n "${3}" ] || [ ! -n "${4}" ]; then
        echo "ERROR! param error, request MYSQL rootPass and masterIp  and bin File and Position num."
        exit 0;
fi

mysql -uroot -p${1} -e "stop slave"
mysql -uroot -p${1} -e "change master to master_host='${2}',master_user='slave',master_password='slave500',master_log_file='${3}' ,master_log_pos=${4};"
mysql -uroot -p${1} -e "start slave;"
sleep 5
status=`echo $(mysql -uroot -p${1} -e "show slave status \G;" | grep -i 'running:')`
echo $status
